<html>
<head><meta charset="utf-8"><title>enum layout optimization · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/enum.20layout.20optimization.html">enum layout optimization</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="203566059"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/enum%20layout%20optimization/near/203566059" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/enum.20layout.20optimization.html#203566059">(Jul 10 2020 at 22:50)</a>:</h4>
<p>Hey, I think there is probably already an issue for this so I don't want to open a new one,<br>
but is there something preventing the following</p>
<div class="codehilite"><pre><span></span><code><span class="k">enum</span> <span class="nc">Foo</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">A</span><span class="p">(</span><span class="kt">usize</span><span class="p">),</span><span class="w"></span>
<span class="w">    </span><span class="n">B</span><span class="p">(</span><span class="o">&amp;</span><span class="nb">&#39;static</span><span class="w"> </span><span class="kt">usize</span><span class="p">,</span><span class="w"> </span><span class="kt">usize</span><span class="p">).</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="n">assert_eq</span><span class="o">!</span><span class="p">(</span><span class="n">std</span>::<span class="n">mem</span>::<span class="n">size_of</span>::<span class="o">&lt;</span><span class="n">Foo</span><span class="o">&gt;</span><span class="p">(),</span><span class="w"> </span><span class="n">std</span>::<span class="n">mem</span>::<span class="n">size_of</span><span class="o">&lt;</span><span class="p">(</span><span class="o">&amp;</span><span class="nb">&#39;static</span><span class="w"> </span><span class="p">(),</span><span class="w"> </span><span class="kt">usize</span><span class="p">)</span><span class="o">&gt;</span><span class="p">());</span><span class="w"></span>
</code></pre></div>


<p><em>edit: zulip doesn't seem to like tables</em></p>
<p>afaict we should be able to set the first <code>std::mem::size_of&lt;&amp;'static ()&gt;()</code> bytes to 0 for <code>Foo::A</code></p>



<a name="203575811"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/enum%20layout%20optimization/near/203575811" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/enum.20layout.20optimization.html#203575811">(Jul 11 2020 at 02:18)</a>:</h4>
<p><span class="user-mention" data-user-id="216206">@lcnr</span> yeah that's a thing I've been wanting to get to for years :(</p>



<a name="203575817"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/enum%20layout%20optimization/near/203575817" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/enum.20layout.20optimization.html#203575817">(Jul 11 2020 at 02:18)</a>:</h4>
<p>there's issues open for it, and some people have taken a stab, but it probably requires a redesign of some stuff to make sense</p>



<a name="203575824"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/enum%20layout%20optimization/near/203575824" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/enum.20layout.20optimization.html#203575824">(Jul 11 2020 at 02:19)</a>:</h4>
<p>there's just too much spaghetti right now in the layout decision logic and it's probably 90% my fault</p>



<a name="203575864"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/enum%20layout%20optimization/near/203575864" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/enum.20layout.20optimization.html#203575864">(Jul 11 2020 at 02:19)</a>:</h4>
<p>(the 10% is what I inherited and tried to preserve, from the old pre-<code>ty::layout</code> stuff that went straight to LLVM)</p>



<a name="203585243"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/enum%20layout%20optimization/near/203585243" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/enum.20layout.20optimization.html#203585243">(Jul 11 2020 at 07:27)</a>:</h4>
<p>Thanks, I found <a href="https://github.com/rust-lang/rust/issues/46213">https://github.com/rust-lang/rust/issues/46213</a></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>